#!/bin/sh
#Usage: directories need to be named with phylum names, such as cyano or chlorobi
#Note: This script runs alignment on each gene, then concatenates them (instead of concat first, then aligning)
#Eg: dissertation_SingleCopyGenes.sh genes.list cyano
#    dissertation_RibosomalGenes.sh r53.list cyano

phylum=$1
count=`wc -l $genes | awk '{print $1}'`

#New. Run alignment for each gene instead of concatenating them and aligning.
#BLAST and extract sequences

cd /host/Users/JS/UH-work/gloeobacter/final_work/comparisons/orthologs/orthomcl/

for i in `cat $phylum.list`;do
    echo "Working on $i and $j"
    cp $i.core.fasta $i.edited.core.fasta
    sed -i 's/>.*/>'$i'/g' $i.edited.core.fasta
done

for i in `cat $genes`;do
    echo "Doing alignments and Gblocks $i"
    #Get each gene ready for alignment
    cat $i*.fasta > $i.align.fasta
    #Run alignment using Muscle
    muscle -in $i.align.fasta -out $i.align.muscle
    #Trim sequences using Gblocks
    Gblocks $i.align.muscle -t=p -e=-gb -b4=2 #output $i.all.muscle-gb
    cp $i.align.muscle-gb /host/Users/JS/UH-work/gloeobacter/final_work/comparisons/ribosomal_genes/
    rm *.htm
    echo "Done!"
done

#Convert/concatenate alignments
dissertation_ConcatConvertMSA.py $genes $phylum.list
cat *.concat.faa > ribo43.each.fasta
dissertation_ConvertAlignment.py ribo43.each.fasta fasta ribo43.each.phy phylip

#Now run RAxML on a Cluster with the following command:
#raxmlHPC-PTHREADS-SSE3 -T 20 -f a -m PROTGAMMAWAG -x 12345 -# 100 -p 11386 -s rc43.muscle-gb.phy -n Ribo43

